package main

import (
	"fmt"
	"os"
)

func main() {
	fileObj, err := os.Open("/Users/bytedance/go/learngo/文件操作/xx.txt") // 绝对路径
	if err != nil {
		fmt.Printf("open file failed %v\n", err)
		return
	}
	defer fileObj.Close() // 延迟关闭
	// 读取文件内容
	var tmp = make([]byte, 128)
	n, err := fileObj.Read(tmp)
	if err != nil {
		fmt.Printf("read from file failed ,err:%v\n", err)
		return
	}
	fmt.Printf("read %d bytes from file\n", n)
	fmt.Println(string(tmp)) //字节类型数据强制转换为字符串类型打印出来
}
